﻿using SIG.WebMVC.Filters;
using System;
using System.Linq;
using System.Security.Claims;
using System.Web.Http;

namespace SIG.WebMVC.Controllers.API
{
    public class DataController : BaseApiController
    {
        [AllowAnonymous]
        [HttpGet]
        [Route("api/data/forall")]
        public IHttpActionResult Get()
        {
            return Ok("Now server time is:" + DateTime.Now.ToString());
        }

        [SigAuthorize]
        [HttpGet]
        [Route("api/data/authenticate")]
        public IHttpActionResult GetForAuthenticate()
        {
            //  return Ok("Hello:" + User.Identity.IsAuthenticated);
            //var identity = (ClaimsIdentity)User.Identity;
            return Ok("Hello:" + ClaimsIdentity.Name);
        }


        [SigAuthorize(Roles ="创始人")]
        [HttpGet]
        [Route("api/data/authorize")]
        public IHttpActionResult GetForAdmin()
        {
            //var identity = (ClaimsIdentity)User.Identity;
            var roles = ClaimsIdentity.Claims.Where(c => c.Type == ClaimTypes.Role)
                .Select(c => c.Value);
            return Ok("Hello:" + ClaimsIdentity.Name + "； Role: " + string.Join(",", roles.ToList()));
        }

    }
}
